package com.hxgis.common.repository.cimiss;

import com.hxgis.cmiss.CimissBaseMapper;
import com.hxgis.cmiss.annotations.CInterfaceId;
import com.hxgis.cmiss.annotations.CMaterial;
import com.hxgis.common.dto.Pre1hAnalyDTO;
import com.hxgis.common.utils.TimeUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.hxgis.common.utils.CollectionUtils.subArrays;

/**
 * 小时数据采集
 */
@Component
@CMaterial("SURF_CHN_MUL_HOR")
public class SurfChnPreMinMapper extends CimissBaseMapper {



    // 根据时间段和站号获取
//    @CInterfaceId("getSurfEleByTimeRangeAndStaID")
//    public List<Pre1hAnalyDTO> getDataByTimeAndstationNoList(String startTime, String endTime, List<String> stationNoList) {
//
//        Map<String,String> params = new HashMap<String, String>();
////        startTime = DateConvertUtil.formatStringToString(startTime, DateConvertUtil.FORMAT_16, DateConvertUtil.FORMAT14_);
////        endTime = DateConvertUtil.formatStringToString(endTime, DateConvertUtil.FORMAT_16, DateConvertUtil.FORMAT14_);
//        params.put("timeRange","[" + TimeUtil.BJTimeToUTC(startTime) + "0000" + "," + TimeUtil.BJTimeToUTC(endTime) + "0000" + "]");
//        params.put("staIds", CollectionUtils.join(stationNo, ","));
//        return getData(nparams,SurfChnPreMin.class);
//    }

    // 多线程执行
    @CInterfaceId("getSurfEleByTimeRangeAndStaID")
    public List<Pre1hAnalyDTO> getDataByTimeAndstationNoListThreads(String startTime, String endTime, List<String> stationNoList) {

        // 按站号的数量 来进行切分任务的数量
        List<Map<String,String>> paramsList = new ArrayList<Map<String,String>>();
        List<String>[] lists = subArrays(stationNoList, 500);
        for (List<String> list : lists) {
            Map<String,String> params = new HashMap<String, String>();
            params.put("timeRange","[" + TimeUtil.BJTimeToUTC(startTime) + "0000" + "," + TimeUtil.BJTimeToUTC(endTime) + "0000" + "]");
            params.put("staIds", StringUtils.join(list, ","));
            paramsList.add(params);
        }
        return getDataList(10,paramsList,Pre1hAnalyDTO.class);
    }


}
